﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Acme.TestSite.Objects
{
	public class MapConfiguration
	{
		public System.Web.UI.Control Control { get; set; }
		public nHydrate.EFCore.DataAccess.INHEntityObject Entity { get; set; }
		public Enum Field { get; set; }
		internal Type Type { get; set; }
		public bool CanHaveRequiredValidation { get; set; }
		public bool ForceRequiredValidation { get; set; }
		public string DataFormatString { get; set; }
		public string ValidationGroup { get; set; }
		public string ErrorMessage { get; set; }
		public string CustomAttribute { get; set; }

		/// <summary>
		/// For a string, this determines if empty string will be saved as a null value
		/// </summary>
		public bool EmptyAsNull { get; set; }

		public bool IsValid()
		{
			if (this.Control == null) return false;
			if (this.Entity == null) return false;
			if (this.Field == null) return false;
			if (this.Type == null) return false;
			return true;
		}

		internal void Setup(nHydrate.EFCore.DataAccess.IContext context)
		{
			if (this.Field != null && this.Type == null)
				this.Type = context.GetFieldType(this.Field);
		}

	}
}
